Don't require all submodules are checked out
authorAlex Crichton <alex@alexcrichton.com>
Thu, 29 Jan 2015 19:41:00 +0000 (11:41 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 29 Jan 2015 19:41:00 +0000 (11:41 -0800)
When probing a repository for files that should be considered as inputs for a
build script we should just skip submodules that haven't been checked out
instead of throwing an error.

Closes #1248

src/cargo/sources/path.rs
tests/test_cargo_compile_git_deps.rs

index 3fc6990f27ecebd7f7c6f4df1dbc09b5f0de04ee..079c892a238eb56a4b17c3be7ea4d07e49eb275c 100644 (file)
@@ -155,7 +155,10 @@ impl<'a, 'b> PathSource<'a, 'b> {
                     human(format!("invalid utf-8 filename: {}", rel.display()))
                 }));
                 let submodule = try!(repo.find_submodule(rel));
-                let repo = try!(submodule.open());
+                let repo = match submodule.open() {
+                    Ok(repo) => repo,
+                    Err(..) => continue,
+                };
                 let files = try!(self.list_files_git(pkg, repo, filter));
                 ret.extend(files.into_iter());
             } else if (*filter)(&file_path) {
index 7555c94a8702a22b9d804a4265733368f2f713e0..e04f2f5ed3e8f89bafc0e13bc149b38401eabe2d 100644 (file)
@@ -6,7 +6,7 @@ use git2;
 use support::{ProjectBuilder, project, execs, main_file};
 use support::{cargo_dir, path2url};
 use support::{COMPILING, UPDATING, RUNNING};
-use support::paths::PathExt;
+use support::paths::{self, PathExt};
 use hamcrest::{assert_that,existing_file};
 use cargo;
 use cargo::util::{ProcessError, process};
@@ -1651,3 +1651,33 @@ test!(switch_sources {
 {compiling} project v0.5.0 ([..])
 ", updating = UPDATING, compiling = COMPILING).as_slice()));
 });
+
+test!(dont_require_submodules_are_checked_out {
+    let project = project("foo");
+    let git1 = git_repo("dep1", |p| {
+        p.file("Cargo.toml", r#"
+            [project]
+            name = "foo"
+            version = "0.5.0"
+            authors = []
+            build = "build.rs"
+        "#)
+        .file("build.rs", "fn main() {}")
+        .file("src/lib.rs", "")
+    }).unwrap();
+    let git2 = git_repo("dep2", |p| p).unwrap();
+
+    let repo = git2::Repository::open(&git1.root()).unwrap();
+    let url = path2url(git2.root()).to_string();
+    add_submodule(&repo, url.as_slice(), &Path::new("submodule"));
+    commit(&repo);
+
+    git2::Repository::init(&project.root()).unwrap();
+    let url = path2url(git1.root()).to_string();
+    let dst = paths::home().join("foo");
+    git2::Repository::clone(&url[], &dst).unwrap();
+
+    assert_that(git1.process(cargo_dir().join("cargo")).arg("build").arg("-v")
+                    .cwd(dst),
+                execs().with_status(0));
+});